package org.sunrise.game.global.main;

import org.sunrise.game.common.config.ConfigReader;
import org.sunrise.game.common.db.DbService;
import org.sunrise.game.common.utils.Utils;
import org.sunrise.game.global.gen.CallEnum;
import org.sunrise.game.rpc.function.CallUtils;
import org.sunrise.game.rpc.node.RpcNodeManager;

import java.util.ArrayList;
import java.util.Properties;

public class GlobalServerStartUp {
    public static void main(String[] args) {
        // args[0]:config path args[1]:global_id
        if (args.length == 0) {
            args = new String[] { "./config/global-config.properties", "2" };
        }
        ConfigReader.loadConfig(args[0]);
        Properties properties = ConfigReader.getProp();
        if (properties == null) {
            return;
        }
        // 设置日志等级
        Utils.setLogLevel(properties.getProperty("log.level"));

        // 创建rpc节点
        var rpcNode = RpcNodeManager.createRpcNode(Integer.parseInt(args[1]));

        // 添加当前模块要注册的rpc
        ArrayList<String> list = new ArrayList<>();
        list.add("org.sunrise.game.global.service.union");
        list.add("org.sunrise.game.global.service.pvp");
        list.add("org.sunrise.game.global.service.chat");
        CallUtils.init(rpcNode.getNodeId(), list, CallEnum.class);

        // 启动
        rpcNode.start(new DbService());
        // 内存检测
        Utils.startMemoryCheck();
    }
}
